﻿using DevExpress.XtraSplashScreen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XCI.Extensions;
using XCI.Sys.Helper;
using XCI.Sys.Model;
using XCI.Windows;
using XCI.Windows.Forms;
using XCI.Windows.Helper;

namespace XCI.Sys.Forms
{
    /// <summary>
    /// 系统报表Ribbon视图模块
    /// </summary>
    [FormCaption("系统报表Ribbon视图模块")]
    public partial class FrmReportRibbonView : FrmBase
    {
        private AsyncWorker asyncWorker = new AsyncWorker();
        private IOverlaySplashScreenHandle handle = null;
        public FrmReportRibbonView()
        {
            InitializeComponent();
        }

        private void FrmReportRibbonView_Load(object sender, EventArgs e)
        {
            //工具栏
            if (ParamData.Get("toolbar", "1").Equals("0"))
            {
                ribbonControl1.Visible = false;
            }
            //状态栏
            if (ParamData.Get("statusbar", "1").Equals("0"))
            {
                ribbonStatusBar1.Visible = false;
            }

            SysReport sysReport = null;
            asyncWorker.RunCallback(p =>
            {
                try
                {
                    handle = SplashHelper.ShowProgressPanel(SysRuntime.MainForm);
                    sysReport = ReportHelper.GetSysReportByParamData(ParamData);
                }
                catch
                {
                    SplashHelper.CloseProgressPanel(handle);
                }
            }).CompletCallback(p =>
            {
                if (sysReport != null)
                {
                    ReportObject.From(sysReport).View(documentViewer1, () =>
                    {
                        SplashHelper.CloseProgressPanel(handle);
                    });
                }
                else
                {
                    SplashHelper.CloseProgressPanel(handle);
                }
            }).RunAsync();
        }
    }
}
